//
//  ReweetedStatusView.swift
//  微博三天
//
//  Created by jessica on 15/11/16.
//  Copyright © 2015年 jessica. All rights reserved.
//
//
import UIKit
import SnapKit
//

class ReweetedStatusView: UIView {

var bottomConstraints : Constraint?

//        数据模型
var retweetedStatus: Status? {
didSet {
    
    //移除底部约束
    self.bottomConstraints?.uninstall()
    //懒加载的控件
    retweetedLabel.text = retweetedStatus?.text
    
    if let picurls = retweetedStatus?.imageURLs where picurls.count > 0 {
        //设置数据源
        pictureView.imageURLs = picurls
        //显示配图
        pictureView.hidden = false//不隐藏
        
        self.snp_makeConstraints(closure: { (make) -> Void in
            
            self.bottomConstraints =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
            
        })
    } else{
        
        pictureView.hidden = true
        self.snp_makeConstraints(closure: { (make) -> Void in
            

            self.bottomConstraints = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
            
        })
        
        
    }
    
}
}
//


//    默认构造
    override init(frame: CGRect) {
        super.init(frame: frame)
        //给个背景的颜色
    backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//设置UI
    private func setupUI() {
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        //设置约束
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
        
//
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
//            make.height.equalTo(100)
//            make.width.equalTo(100)
        }
        
        self.snp_makeConstraints { (make) -> Void in
//            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
            self.bottomConstraints = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
        
    
    }
//    懒加载
    private lazy var retweetedLabel : UILabel = UILabel(title: "我是转发微博", size: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    
    private lazy var pictureView : StatusPictureView = StatusPictureView()

}

